<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html class="ui-mobile">
<head>
<link href="http://static.image.alimmdn.com/favicon.ico?t=123654" rel="shortcut icon">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="user-scalable=no">
<title>选择地址</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css">
<style type="text/css">
	body{
		font-family:"Microsoft YaHei";
	}
	span,a{
		font-size: 42px;
		color: #39ad36;
	}
	h1{
		color: #39ad36;
	}
</style>
</head>
<body class="ui-mobile-viewport ui-overlay-a">
	<div data-role="page" style="margin: 0;">
		<div role="main" class="ui-content" style="font-size: 42px;">
			<form action="/activity/addAddr" method="POST" onsubmit="checkVal()">
				<input id="name" style="margin: 10px 0;font-size: 45px;" placeholder="请输入联系人姓名">
				<input id="telephone" style="margin: 10px 0;font-size: 45px;" placeholder="请输入联系电话">
				<input id="addr" style="margin: 10px 0;font-size: 45px;" placeholder="请输入详细地址">
				<a href="#" class="ui-btn" style="background-color: #39ad36;padding: 35px 0;" onclick="checkVal()">
					<span style="color: #ffffff;font-size:45px;">添加地址</span>
				</a>
			</form>
			<label style="font-size: 42px;color: #666666;padding: 15px 0;">常用地址</label>
			<c:forEach items="${list}" var="addr">
				<a href="javascript:void(0)" style="text-decoration: none;" class="caddr" onclick="selectAddr(${addr.addressid})">
					<div style="margin: 15px 0;background-color: #EEEEEE;padding: 0 20px;">
						<div style="padding: 15px 0;">
							<span style="font-size: 45px;">${addr.name}</span>
							<span style="float: right;font-size: 45px;">${addr.telephone}</span>
						</div>
						<div style="padding: 15px 0;">
							<span style="color: #666666;font-size: 45px;">${addr.text}</span>
						</div>
					</div>
				</a>
			</c:forEach>
		</div><!-- /content -->
	</div>
	<div data-role="popup" id="popupBasic">
		<h3 style="text-align:center;">提示</h3>
	    <p id="message"></p>
	</div>
<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript">
var userId = ${userId};
function checkVal(){
    var name = $("#name").val();
    var telephone = $("#telephone").val();
    var addr = $("#addr").val();
    if (!name){
        alert('请输入用户名');
        return false;
    }
    if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(telephone))){
    	alert('请输入正确的手机');
    	return false;
    }
    if (!addr) {
        alert('请输入地址');
        return false;
    }
    var params = {
        'name':name,
        'telephone':telephone,
        'text':addr,
        'userid':userId
    }
    var url = '<c:url value = "/activity/addAddr"/>';
    $.post(url,params,function(data){
    	if(data.code==0){
    		history.back();
    	}
    },"json");
}

function selectAddr(addrId){
	var url = '<c:url value = "/activity/selectAddrId"/>';
	var params={
			'addrId':addrId
	}
    $.post(url,params,function(data){
    	if(data.code==0){
			var url = '<c:url value="/activity/makeOrder"/>?userId='+userId;
			location.href=url;
		}
    },"json");
}
</script>
</body>
</html>